#ifndef _COMMUNICATE_H_
#define _COMMUNICATE_H_

#include <pthread.h>


//通信协议帧定义
typedef enum
{
	SERVER_HEAD1 = 0x00,
	SERVER_HEAD2 = 0x01,
	SERVER_LEN = 0x02,
	SERVER_OPERATE = 0x03,
	SERVER_DEVICETYPE = 0x04,
	SERVER_DEVICENAME = 0x05,
	SERVER_DATA = 0x06,
	SERVER_CHECK = 0x07,
	
}ENUM_SERVER_STATE;

//数据接收的消息队列
typedef struct sss{
	uint8_t	Len;
	uint8_t Operate;
	uint8_t	DeviceType;
	uint8_t	DeviceName;
	DATA32_t Data;				//注意，若是有符号数，请进行强制转换
}ServerCmdStruct;

typedef union{
	uint8_t RecvData[ETH_CMD_LENGTH];
	ServerCmdStruct RecvDatastruct;
}ServerRecvCmd_t;


typedef enum{
 	UART_HEAD1 = 0x00,
	UART_HEAD2 = 0x01,
	UART_OPERATE = 0x02,
	UART_TYPE = 0x03, 
    UART_DATA = 0x04,  
    UART_CHACK = 0x05,
}ENUM_UART_STATE;

typedef struct urc{
  	uint8_t	operate;
	uint8_t deviceType;
    DATA16_t  data;
}UartCmdStruct;

typedef union{
    uint8_t cmddata[UART_CMD_LENGTH];
    UartCmdStruct cmdstruct;
}UartRecvCmd_t;

typedef enum{
	POWER_PERCENT_TYPE = 0xa0,
	GYRO_YZHOU_TYPE = 0xa1,
	DISTANCE_RADAR_TYPE = 0xa2,

}ENUM_CMD_LIST;



void comm_init(void);


void recv_eth_data(const char *buff,const unsigned int len);    //接受线程调用
void servertaskdistribute(ServerCmdStruct *RecvDataBuff);       //任务线程中调用
void eth_cmd_package(uint8_t operate, uint8_t devicetype, uint8_t devicename,uint32_t data);
void eth_send_package(uint8_t *buff);

void recv_uart_data(const char *buff,const unsigned int len);   //接受线程调用
void uart_updata(UartRecvCmd_t *recvbuff);
void uart_cmd_package(uint8_t operate, int8_t davicetype, int16_t data);
void uart_send_package(uint8_t *buff);

void recv_udp_data(const char *buff, const unsigned int len);
void udp_cmd_package(uint8_t destip,uint16_t destport, const uint8_t *data, uint8_t len);
void udp_send_package(uint8_t destip,uint16_t destport, uint8_t *data, uint8_t len);
#endif // !_COMMUNICATE_H_
